package com.zhaozhaonews.article.listener;


import com.alibaba.fastjson.JSON;
import com.zhaozhaonews.article.service.ApArticleConfigService;
import com.zhaozhaonews.common.constants.WmNewsMessageConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.net.nntp.Article;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author WanJl
 * @version 1.0
 * @title ArticleIsDownListener
 * @description 监听新闻下架消息
 * @create 2025/2/20
 */
@Component
@Slf4j
public class ArticleIsDownListener {

    @Resource
    private ApArticleConfigService apArticleConfigService;

    @KafkaListener(topics = WmNewsMessageConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void onMessageArrived(String message) {
        log.info("接到通知.......，{}",message);
        if (StringUtils.isNotBlank(message)) {
            Map map = JSON.parseObject(message, Map.class);
            apArticleConfigService.updateByMap(map);
            log.info("article端新闻配置修改，articleId={}", map.get("articleId"));
        }
    }


}
